<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyle.html">
</head>
<body>
<div class="layui-tab layui-tab-card" style="margin: 0 6px" lay-filter="test1">
    <ul class="layui-tab-title">
        <li class="" lay-id="parameter" >个人常用语设置</li>
        <li lay-id="process" >根据流程设置</li>
        <li lay-id="" >根据流程分类设置</li>
        <li lay-id="" >全局设置</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form">
                <input type="hidden" name="type" value="4"/>
                <table class="table-detail" style="margin: 0">
                    <tbody>
                        <tr>
                            <th>
                                常用语
                            </th>
                            <td>
                                <textarea  class="layui-textarea" rows="4" name="approvalItem" id="approvalItem" style="width: 270px; float: left;margin: 5px"></textarea>
                                <i class="layui-icon layui-icon-help taskApprovalItemsTips"></i>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>

        <div class="layui-tab-item">
            <input type="hidden" name="type" value="3"/>
            <div class="panel-detail">
                <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <th>流程定义:</th>
                        <td >
                            <input type="hidden" id="refDefKey" name="refDefKey"/>
                            <p id="referDefinitionSpan"></p>
                            <a class="layui-btn layui-btn-danger layui-btn-xs "id="referDefinition">选择流程</a>
                        </td>
                    </tr>
                    <tr>
                        <th>常用语</th>
                        <td>
                            <textarea  class="layui-textarea"  name="approvalItem" rows="4" style="width: 270px; float: left;margin: 5px"></textarea>
                            <i class="layui-icon layui-icon-help taskApprovalItemsTips"></i>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="layui-tab-item">
            <input type="hidden" name="type" value="2"/>
            <div class="panel-detail">
                <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                    <tr id="trFlowType">
                        <th>流程分类: </th>
                        <td>
                            <div id="flowTypeDiv">
                                <input type="hidden" id="refFlowKey" name="refFlowKey"/>
                                <p id="flowTypeArray"></p>
                                <a class="layui-btn layui-btn-danger layui-btn-xs" id="flowTypeArrayBtn">选择流程分类</a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>常用语</th>
                        <td>
                            <textarea  class="layui-textarea" name="approvalItem" rows="4" style="width: 270px; float: left;margin: 5px"></textarea>
                            <i class="layui-icon layui-icon-help taskApprovalItemsTips"></i>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="layui-tab-item">
            <input type="hidden" name="type" value="1"/>
            <div class="panel-detail">
                <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <th>常用语</th>
                        <td>
                            <textarea  class="layui-textarea" name="approvalItem" rows="4" style="width: 270px; float: left;margin: 5px"></textarea>
                            <i class="layui-icon layui-icon-help taskApprovalItemsTips"></i>
                        </td>
                    </tr>
                </table>
            </div>
        </div>

    </div>
</div>
<textarea id="tbodyPreview"  style="display: none;" >
			<tr>
				<td>发起人:</td>
				<td>
					<input type="text" name="startUserId" readonly="readonly" value="" previewId=""/>
					<a class="button"><span class="chosen">选择</span></a>
				</td>
			</tr>
</textarea>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer', 'form', 'element','setter','jquery','table'], function() {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.jquery
            ,table = layui.table
            ,setter = layui.setter
            , element = layui.element;
        var isAdmin = ${isAdmin?string ('true','false')};

        if (!isAdmin){
            $(".layui-tab-title li").each(function (index,val) {
                if (index!==0){
                    $(".layui-tab-title li").eq(index).hide();
                }
            });
            element.tabChange('test1', "parameter");
        }else {
            $(".layui-tab-title li").each(function (index,val) {
                $(".layui-tab-title li").eq(0).hide();
                if (index!==0){
                    $(".layui-tab-title li").eq(index).show();
                }
            });
            element.tabChange('test1', "process"); //假设当前地址为：http://a.com#test1=222，那么选项卡会自动切换到“发送消息”这一项
        }
        $(".taskApprovalItemsTips").mouseover(function () {
            layer.tips('规范输入常用语', this);
        });
        // 选择授权流程弹窗
        $("#referDefinition").click(function(){
            var actSelectWin;
            var body;
            parent.layer.open({
                type: 2,
                title: '选择流程',
                resize:false,
                area: ['1000px', '600px'],
                btn:["保存","取消"],
                content: serverPath.workflowPath + setter.workflowLinkPath + 'bpmDefAuthorize/view/actDialog',
                shadeClose: false,
                success: function(layero, index){
                    body = parent.layer.getChildFrame('body',index);
                    actSelectWin = parent.window[layero.find('iframe')[0]['name']];
                    // 初始化已选择的流程
                    actSelectWin.layui.actList = [];
                    if($("#referDefinitionSpan span").length>0){
                        for (var i = 0; i < $("#referDefinitionSpan span").length; i++) {
                            actSelectWin.layui.actList.push({
                                defKey:$("#referDefinitionSpan span").eq(i).attr("value"),
                                defName:$("#referDefinitionSpan span").eq(i).attr("name")
                            });
                        }
                    }
                },
                yes: function(index,layero){
                    var theUserList = body.find("input[name=actList]").val();
                    //清除之前选择的流程
                    $("#referDefinitionSpan").html("");
                    //重新赋值
                    if(theUserList!=="[]"){
                        var TableData = JSON.parse(theUserList);
                        $.each(TableData,function (index,val) {
                            $("#referDefinitionSpan").append("<span style='margin-right: 5px' name='"+val.defName+"' value='"+val.defKey+"'>"+val.defName+"<a href='javascript:void(0);' class='layui-badge-rim delRefer'>删除</a></span>")
                        });
                    }
                    parent.layer.close(index);
                }
            });
        });
        // 选择流程分类弹窗
        $("#flowTypeArrayBtn").click(function(){
            var actSelectWin;
            var body;
            parent.layer.open({
                type: 2,
                title: '选择流程分类',
                resize:false,
                area: ['800px', '600px'],
                btn:["保存","取消"],
                content: serverPath.workflowPath + setter.workflowLinkPath + 'actDefModel/view/treeList',
                shadeClose: false,
                success: function(layero, index){
                    body = parent.layer.getChildFrame('body',index);
                    actSelectWin = parent.window[layero.find('iframe')[0]['name']];
                    // 初始化已选择的流程
                    actSelectWin.layui.actList = [];
                    if($("#flowTypeArray span").length>0){
                        for (var i = 0; i < $("#flowTypeArray span").length; i++) {
                            actSelectWin.layui.actList.push({
                                defKey:$("#flowTypeArray span").eq(i).attr("value"),
                                defName:$("#flowTypeArray span").eq(i).attr("name")
                            });
                        }
                    }
                },
                yes: function(index,layero){
                    var theUserList = body.find("input[name=actList]").val();
                    //清除之前选择的流程分类
                    $("#flowTypeArray").html("");
                    //重新赋值
                    if (theUserList!==""){
                        var TableData = JSON.parse(theUserList);
                        $.each(TableData,function (index,val) {
                            $("#flowTypeArray").append("<span style='margin-right: 5px' value='"+val.defKey+"' name='"+val.defName+"'>"+val.defName+"<a href='javascript:void(0);' class='layui-badge-rim delRefer'>删除</a></span>")
                        });
                    }
                    parent.layer.close(index);
                }
            });
        });
        //删除
        $(document).on('click','.delRefer',function(){
            $(this).parent().remove();
        })
    })
</script>
</body>
</html>